package org.smartjava.concurrent.core;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;

public class WayOfCreatThread {


    public static void main(String[] args) throws ExecutionException, InterruptedException {


        //        //        FutureTask<String> futureTask = new FutureTask<>(new MyCallable());
        //        //        new Thread(futureTask).start();
        //        //        System.out.println(futureTask.get());
        Executors.newSingleThreadExecutor().submit(() -> {
            System.out.println("通过线程池来创建线程");
        });
    }

    public static void byThread() throws ExecutionException, InterruptedException {
        new MyThread().start();
        new Thread(new MyRunnable()).start();
    }

}

class MyThread extends Thread {
    @Override
    public void run() {
        System.out.println("通过继承Thread实现多线程");
    }
}

class MyRunnable implements Runnable {
    @Override
    public void run() {
        System.out.println("通过实现Runnable实现多线程");
    }
}

class MyCallable implements Callable<String> {
    @Override
    public String call() {
        return "通过实现Callable实现多线程";
    }
}